package com.l2device.gameserver.custom.deamon;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import com.l2device.gameserver.L2DatabaseFactory;
import com.l2device.gameserver.model.L2World;
import com.l2device.gameserver.model.actor.instance.L2PcInstance;

public class VoteUtils
{
	public static L2PcInstance loadPlayer(String charName)
	{
		L2PcInstance result = L2World.getInstance().getPlayer(charName);
		if (result == null)
		{
			try (Connection con = L2DatabaseFactory.getInstance().getConnection())
			{
				PreparedStatement stm = con.prepareStatement("select obj_Id from characters where char_name like ?");
				stm.setString(1, charName);
				ResultSet r = stm.executeQuery();
				if (r.next())
				{
					result = L2PcInstance.restore(r.getInt(1));
				}
				r.close();
				stm.close();
			}
			catch (SQLException e)
			{
				result = null;
			}
		}
		return result;
	}
}